{% load staticfiles %}


<!DOCTYPE html>
<html style="overflow-x:auto;overflow-y:auto;">
<head>
	<title>机构列表</title>
	
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="author" content="http://www.jeeplus.org/"/>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=9,IE=10" />
<meta http-equiv="Expires" content="0">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Cache-Control" content="no-store">
<script>var d = "";</script>
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
{% include 'base.html' %}

<script type="text/javascript">

    $(document).ready(function(){
        $('input.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });
    });


</script>

	
	
	<meta name="decorator" content="ani"/>
	
<script>
	var $treeTable=null;  
	$(document).ready(function() {
		$treeTable=$('#treeTable').treeTable({  
	    	   theme:'vsStyle',	           
				expandLevel : 2,
				column:0,
				checkbox: false,
	            url:'/system/office/getChildren/?parentId=',  
	            callback:function(item) { 
					//alert(item)
	            	var officeItemTpl= $("#officeItemTpl").html();
					//item.typeLabel = jp.getDictLabel([{"id":"21","createBy":{"id":"1","loginFlag":"1","roleNames":"","admin":true},"createDate":"2013-05-27 08:00:00","updateBy":{"id":"1","loginFlag":"1","roleNames":"","admin":true},"updateDate":"2013-05-27 08:00:00","label":"公司","value":"1","sort":"60","dictType":{"id":"19"}},{"id":"22","createBy":{"id":"1","loginFlag":"1","roleNames":"","admin":true},"createDate":"2013-05-27 08:00:00","updateBy":{"id":"1","loginFlag":"1","roleNames":"","admin":true},"updateDate":"2013-05-27 08:00:00","label":"部门","value":"2","sort":"70","dictType":{"id":"19"}},{"id":"23","createBy":{"id":"1","loginFlag":"1","roleNames":"","admin":true},"createDate":"2013-05-27 08:00:00","updateBy":{"id":"1","loginFlag":"1","roleNames":"","admin":true},"updateDate":"2013-05-27 08:00:00","label":"小组","value":"3","sort":"80","dictType":{"id":"19"}},{"id":"24","createBy":{"id":"1","loginFlag":"1","roleNames":"","admin":true},"createDate":"2013-05-27 08:00:00","updateBy":{"id":"1","loginFlag":"1","roleNames":"","admin":true},"updateDate":"2013-05-27 08:00:00","label":"其它","value":"4","sort":"90","dictType":{"id":"19"}}], item.type);
                    var result = laytpl(officeItemTpl).render(item);
	                return result;
	            },  
	            beforeClick: function($treeTable, id) { 
	                //异步获取数据 这里模拟替换处理  
	                $treeTable.refreshPoint(id);  
	            },  
	            beforeExpand : function($treeTable, id) {   
	            },  
	            afterExpand : function($treeTable, id) {  
	            	//layer.closeAll(); 
	            },  
	            beforeClose : function($treeTable, id) {    
	            	
	            }  
	        });  
	       
	});
	
	function del(con,id){  
		jp.confirm('确认要删除机构吗？', function(){
			jp.loading();
       	  	$.get("/system/office/del/?id="+id, function(data){
       	  		if(data.success){
       	  			$treeTable.del(id);
       	  			jp.success(data.msg);
       	  		}else{
       	  			jp.error(data.msg);
       	  		}
       	  	})
       	   
   		});

	} 
	
	function refresh(){//刷新
		var index = jp.loading("正在加载，请稍等...");
		$treeTable.refresh();
		jp.close(index);
	}
	function refreshNode(data) {
		refresh();
		return;
		alert(data)
        var current_id = data.body.office.id;
        var target = $treeTable.get(current_id);
        var old_parent_id = target.attr("pid") == undefined?'0':target.attr("pid");
        var current_parent_id = data.body.office.parentId;
        var current_parent_ids = data.body.office.parentIds;

        if(old_parent_id == current_parent_id){
            if(current_parent_id == '0'){
                $treeTable.refreshPoint(-1);
            }else{
                $treeTable.refreshPoint(current_parent_id);
            }
        }else{
            $treeTable.del(current_id);//刷新删除旧节点
            $treeTable.initParents(current_parent_ids, "0");
        }
    }
</script>
<script type="text/html" id="officeItemTpl">
	<td><a  href="#" onclick="jp.openViewDialog('View Office', '/system/office/view/?id={% verbatim %}{{d.id}}{% endverbatim %}','800px', '600px')">{% verbatim %}{{d.name}}{% endverbatim %}</a></td>
	<td>{% verbatim %}{{d.code}}{% endverbatim %}</td>
	
<td>
	<div class="btn-group">
 		<button type="button" class="btn  btn-primary btn-xs dropdown-toggle" data-toggle="dropdown">
			<i class="fa fa-cog"></i>
			<span class="fa fa-chevron-down"></span>
		</button>
	  <ul class="dropdown-menu" role="menu">
		
			<li><a href="#" onclick="jp.openViewDialog('View Office', '/system/office/view/?id={% verbatim %}{{d.id}}{% endverbatim %}','800px', '600px')"  ><i class="fa fa-search-plus"></i>  View</a></li>
		
		
			<li><a href="#" onclick="jp.openSaveDialog('Edit Office', '/system/office/edit/?id={% verbatim %}{{d.id}}{% endverbatim %}','800px', '600px')" ><i class="fa fa-edit"></i> Edit</a></li>
		
		
			<li><a  onclick="return del(this, '{% verbatim %}{{d.id}}{% endverbatim %}')"><i class="fa fa-trash"></i> Delete</a></li>
		
		<!--
			<li><a href="#" onclick="jp.openSaveDialog('Add Sub Office', '/system/office/form/?parent.id={% verbatim %}{{d.id}}{% endverbatim %}','800px', '600px')"><i class="fa fa-plus"></i> Add Sub Office</a></li>
		-->
	  </ul>
	</div>
</td>
</script>

</head>
<body id="" class=""  style="">
	
	<div class="wrapper wrapper-content">
		<div class="panel panel-primary">
			<div class="panel-heading">
				<h3 class="panel-title">机构列表</h3>
			</div>
			
			<div class="panel-body">
			<!-- 工具栏 -->
			<div class="row">
			<div class="col-sm-12">
				<div class="pull-left treetable-bar">
					
						<a id="add" class="btn btn-primary"  onclick="jp.openSaveDialog('Add Office', '/system/office/add/','800px', '600px')" ><i class="glyphicon glyphicon-plus"></i> 新建</a>
					
			       <button class="btn btn-default" data-toggle="tooltip" data-placement="left" onclick="refresh()" title="刷新"><i class="glyphicon glyphicon-repeat"></i> 刷新</button>
				
				</div>
			</div>
			</div>
		
			<table id="treeTable" class="table table-hover">
				<thead>
					<tr>
						<th>机构名称</th>
						<th>机构编码</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
				</tbody>
			</table>
			<br/>
			</div>
		</div>
	</div>

</body>
</html>